/*
 * http://www.digione.cn
 */
package com.jqd.examples.struts2.converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;

/**
 * TODO
 * 
 * @author liaozc@digione.cn
 * @date 2012-8-9
 * @since 1.0
 */
public class DateTypeConverter extends DefaultTypeConverter {
	
	@SuppressWarnings("rawtypes")
	@Override
	public Object convertValue(Map<String, Object> context, Object value, Class toType) {
		System.out.println(value);
		System.out.println(value.getClass());
		
		DateFormat format = new SimpleDateFormat("yyyymmdd");
		
		if (toType == Date.class) {
			String[] vs = (String[]) value;
			try {
				return format.parse(vs[0]);
			}
			catch (ParseException e) {
				e.printStackTrace();
			}
		}
		
		return value;
	}
	
}
